<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <meta name="copyright" content=
    "Copyright (c) IBM Corporation and others 2000, 2011. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." />
    <meta http-equiv="Content-Type" content=
    "text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="stylesheet" href="../book.css" charset="ISO-8859-1"
    type="text/css" />
    <title>
      Running your programs
    </title>
    <script language="JavaScript" type="text/javascript" src=
    "PLUGINS_ROOT/org.eclipse.help/livehelp.js">

</script>
  </head>
  <body>
    <h1>
      Running Your Programs
    </h1>
    <p>
      In this section, you will learn more about running Java
      programs in the workbench.
    </p>
    <ol>

      <li>In the Package Explorer view, find
      <em>junit.textui/TestRunner.java</em> and double-click it to
      open it in an editor.
      </li>
      <li>In the Outline view, notice that the TestRunner class has
      an icon which indicates that the class defines a
      <code>main</code> method.
        <p>
          <img src="images/view_outline_testrunner_main.png" alt=
          "Outline view with selected TestRunner class" />
        </p>
      </li>

      <li>Right click on TestRunner.java in the Package Explorer
      and select <strong>Run As</strong> &gt; <strong>Java
      Application</strong>. This will launch the selected class as
      a local Java application. The <strong>Run As</strong> context
      menu item is also available in other places, such as the
      Outline view.
        <p>
          <img src="images/view_outline_testrunner_run.png" alt=
          "Run context menu" />
        </p>
      </li>

      <li>Notice that the program has finished running and the
      following message appears in the Console view telling you
      that the program needs an execution argument.&nbsp; Running
      class from the Package Explorer as a Java Application uses
      the default settings for launching the selected class and
      does not allow you to specify any arguments.
        <p>
          <img src="images/view_console_noarg.png" alt=
          "Console with error message: Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class" />
        </p>
      </li>
      <li>To specify arguments, use the drop-down
      <strong>Run</strong> menu in the toolbar and select <strong>

        Run Configurations...</strong>.
        <p>
          <img src="images/open_run_dialog.png" alt=
          "Run menu of the toolbar" />
        </p>You can also Ctrl+Click a configuration in the
        drop-down menu to start editing that configuration.
      </li>
      <li>This time, the Launch Configurations dialog opens with
      the TestRunner launch configuration selected. A launch
      configuration allows you to configure how a program is
      launched, including its arguments, classpath, and other
      options.&nbsp; (A default launch configuration was created
      for you when you chose <strong>Run &gt; Java
      Application</strong>).
        <p>

          <img src="images/run_dialog.png" alt=
          "Launch configuration dialog showing the Main tab" />
        </p>
      </li>
      <li>Select the Arguments tab and type
      <em>junit.samples.VectorTest</em> in the Program arguments
      area.
        <p>
          <img src="images/run_dialog_arguments.png" alt=
          "Arguments tab of the launch configuration dialog" />
        </p>
      </li>

      <li>Click <strong>Run</strong>. This time the program runs
      correctly, indicating the number of tests that were run.
        <p>
          <img src="images/view_console_success.png" alt=
          "Console showing program output" />
        </p>
      </li>
      <li>
        <p>
          Switch to the Debug perspective. In the Debug view,
          notice that a process for the last program launch was
          registered when the program was run.
        </p>

        <p>
          By default, the Debug view automatically removes any
          terminated launches when a new launch is created. This
          preference can be configured on the <a class=
          "command-link" href=
          'javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)")'>
          <img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg"
          alt="Goto the Launching preference page" />
          <strong>Run/Debug &gt; Launching</strong></a> preference
          page
        </p>
        <p>
          <img src="images/view_debug.png" alt=
          "Debug view showing two terminated run launches" />

        </p><em>Note: You can relaunch a terminated process by
        selecting <strong>Relaunch</strong> from its context
        menu.</em>
      </li>
      <li>Select the drop-down menu from the <strong>Run</strong>
      button in the workbench toolbar. This list contains the
      previously launched programs. These programs can be
      relaunched by selecting them in the history list.
        <p>
          <img src="images/run_dropdown.png" alt=
          "Run drop down menu from the workbench toolbar" />

        </p>
      </li>
      <li>By default the currently selected resource or active
      editor is launched when the run button is hit. If none of
      these is launchable the current project will be launched. You
      can configure this behavior under <a class="command-link"
      href=
      'javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)")'>
        <img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg"
        alt="Goto the Launching preference page" />
        <strong>Run/Debug &gt; Launching</strong></a>.
        <p>
          <img src="images/pref_launch_operation.png" alt=
          "Debug view showing two terminated run launches" />

        </p>
      </li>
      <li>From the context menu in the Debug view (or the
      equivalent toolbar button), select <strong>Remove All
      Terminated</strong> to clear the view of terminated launch
      processes.
        <p>
          <img src="images/view_debug_removelaunched.png" alt=
          "Debug view showing context menu" />
        </p>
      </li>
    </ol>

    <p class="nav_footer" id="nav_footer">
      Next Section: <a href="qs-13.htm">Debugging your programs</a>
    </p>

    <h3 class="related">Related Tasks</h3>
      <a href="../tasks/tasks-9.htm">Changing debugger launch
      options</a><br />
      <a href=
      "../tasks/task-remotejava_launch_config.htm">Connecting to a
      remote VM with the Remote Java application launch
      configuration</a><br />

      <a href=
      "../tasks/task-disconnect_remote_debug.htm">Disconnecting
      from a VM</a><br />
      <a href="../tasks/task-launching_java_program.htm">Launching
      a Java program</a><br />
      <a href="../tasks/task-running_and_debugging.htm">Running and
      debugging</a><br />

    <h3 class="related">Related Reference</h3>
      <a href="../reference/views/debug/ref-debug_view.htm">Debug
      view</a><br />
      <a href="../reference/menus/run/ref-menu-run.htm">Run menu
      actions</a><br />
      <a href="../reference/ref-toolbar-run.htm">Run and debug
      toolbar actions</a><br />
  </body>
</html>
